package tech.veedo.munchkin.verifications.frontend.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import tech.veedo.munchkin.beans.frontend.Form;
import tech.veedo.munchkin.constants.Operation;
import tech.veedo.munchkin.verifications.frontend.FormVerify;

@Slf4j
@Service
public class FormVerifyImpl implements FormVerify {

    @Override
    public boolean verify(Operation operation, Form form) {
        switch (operation) {
            case ADD:
                addVerify(form);
            case UPDATE:
                updateVerify(form);
            default:
                return true;
        }
    }

    private void addVerify(Form form) {
        titleNotNull(form.getTitle());
        typeNotNull(form.getType());
        commitPsnIDNotNull(form.getCommitPsnID());
        commitPostCodeNotNull(form.getCommitPostCode());
        auditingIDNotNull(form.getAuditingID());
    }

    private void updateVerify(Form form) {
    }

    private void titleNotNull(String title) {
        if (StringUtils.isEmpty(title)) {
            throw new NullPointerException("审批表单的标题为空");
        }
    }
    private void typeNotNull(Integer type) {
        if (ObjectUtils.isEmpty(type)) {
            throw new NullPointerException("审批表单的类型为空");
        }
    }
//    private void workflowIDNotNull(Long workflowID) {
//        if (ObjectUtils.isEmpty(workflowID)) {
//            throw new NullPointerException("审批表单的顶层工作流标识为空");
//        }
//    }
//    private void belongOrgCodeNotNull(String belongOrgCode) {
//        if (StringUtils.isEmpty(belongOrgCode)) {
//            throw new NullPointerException("审批表单的机构编码标识为空");
//        }
//    }
    private void commitPsnIDNotNull(String commitPsnID) {
        if (StringUtils.isEmpty(commitPsnID)) {
            throw new NullPointerException("审批表单的提交人员标识为空");
        }
    }
    private void commitPostCodeNotNull(String commitPostCode) {
        if (StringUtils.isEmpty(commitPostCode)) {
            throw new NullPointerException("审批表单的提交人员岗位编码为空");
        }
    }
    private void auditingIDNotNull(String auditingID) {
        if (StringUtils.isEmpty(auditingID)) {
            throw new NullPointerException("审批表单的审核项标识为空");
        }
    }
}
